package de.uulm.vs.timeserverv3;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by wymaoxiaoliang on 2017/3/2.
 */
public class UnixTime {
    private final long value;

    public UnixTime() {
        this(System.currentTimeMillis() / 1000L + 2208988800L);
    }

    public UnixTime(long value) {
        this.value = value;
    }

    public long value() {
        return value;
    }

    /**
     * 获取时间字符串(yyyy-MM-dd HH:mm:ss)
     *
     * @return 返回字符串格式 yyyy-MM-dd HH:mm:ss
     */
    @Override
    public String toString() {
        SimpleDateFormat formatter = new SimpleDateFormat("北京时间: yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(new Date((value() - 2208988800L) * 1000L));
        return dateString;
    }
}
